<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="/sb/js/jquery-1.8.3.js"></script>
</head>
<body>
<center>
  <h1>部门更新</h1>
  <table>
    <tbody>
    <tr>
      <td>部门编号</td><td><input  id="deptno" type="text"></td>
    </tr>
    <tr>
      <td>部门名字</td><td><input  id="dname" type="text"></td>
    </tr>
    <tr>
      <td>部门位置</td><td><input id="loc" type="text"></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input onclick="insertNews()" type="button" value="更新"></td>
    </tr>
    </tbody>
  </table>
</center>
<script>
    $(function(){
        var urlinfo=window.location.href;
        var offset=window.location.search;//设置参数字符串开始的位置
        var deptNo = offset.split("&")[0].split("=")[1];
        alert(deptNo);
        $.get(
            "/sb/dept/selectDeptById",
            {deptNo:deptNo},
            function(data) {
                alert(data);
                if(data!=''){
                    $("#typeName").empty();
                    for(var i = 0;i<data.length;i++){
                        $("#deptno").val(data[i].DEPTNO);
                        $("#dname").val(data[i].DNAME);
                        $("#loc").val(data[i].LOC);
                    }
                }
            },
            "json"
        );
    });

    //更新按钮
    function insertNews() {
        var dname = $("#dname").val();
        var loc = $("#loc").val();
        var deptno = $("#deptno").val();
        $.get(
            "/sb/dept/updateDeptMsg",
            {dname:dname,loc:loc,deptNo:deptno},
            function(data) {
                alert(data.msg);
                location.href="list.html";
            },
            "json"
        );
    }
</script>
</body>
</html>
